// 签名
import _bale from '../utils/package.js'
// 获取不同的接口地址
import {
  COMMON_API,
  SHARE_API,
  SSO_API,
  ACTIVITY_API
} from '../config/index.js'
import { Service } from '../utils/server.js'
const App = getApp()
class AppModel extends Service {
  // 查看环境标识信息
  queryEnv(params) {
    return this.postRequest(SHARE_API + '/task/queryEnv', {
      data: _bale('queryEnv', params)
    })
  }
  // 获取七牛云token
  getQiniuUptoken(params) {
    return this.postRequest(COMMON_API + '/qiniu/get_token', {
      data: _bale('get_token', params)
    })
  }

  getCodeUrl(params) {
    return this.postRequest(SHARE_API + '/red/getWXACodeUnlimit', {
      data: _bale('getWXACodeUnlimit', params)
    })
  }
  //发红包
  getRedPacket(params) {
    return this.postRequest(SHARE_API + '/red/addRed', {
      data: _bale('addRed', params)
    })
  }
  //领红包
  collarRed(params) {
    return this.postRequest(SHARE_API + '/red/collarRed', {
      data: _bale('collarRed', params)
    })
  }

  //看看大家手气
  handRed(params) {
    return this.postRequest(SHARE_API + '/red/handRed', {
      data: _bale('handRed', params)
    })
  }
  //获取售前售后信息
  getCustomerService(params) {
    return this.postRequest(COMMON_API + '/ruleCommon/querySalesService', {
      data: _bale('querySalesService', params)
    })
  }
  // 新增粉丝  绑定上一级的用户id
  addFans(params) {
    return this.postRequest(SHARE_API + '/vipUser/add_fans', {
      data: _bale('add_fans', params)
    })
  }
  newUserRed(params) {
    return this.postRequest(SHARE_API + '/red/newCollarRed', {
      data: _bale('newCollarRed', params)
    })
  }

  //查询订单、售后数量
  selectNumber(params) {
    return this.postRequest(ACTIVITY_API + '/shopCart/selectNumber', {
      data: _bale('selectNumber', params)
    })
  }

  //查询购物车数量
  selectCartNumber(params) {
    return this.postRequest(ACTIVITY_API + '/shopCart/selectCartNumber', {
      data: _bale('selectCartNumber', params)
    })
  }

  //获取红包是否启用
  getRedFlag(params) {
    return this.postRequest(COMMON_API + '/ruleCommon/queryRed', {
      data: _bale('queryRed', params)
    })
  }
  // 添加分享记录
  addShare(params) {
    return this.postRequest(SHARE_API + '/applietLazy/addShare', {
      data: _bale('addShare', params)
    })
  }

  //添加formId
  add_formId(params) {
    return this.postRequest(SHARE_API + '/wxPush/add_formId', {
      data: _bale('add_formId', params)
    })
  }
  // 获取用户信息
  _getVipInfo() {
    const token = wx.getStorageSync('utoken')
    return this.postRequest(SSO_API + '/vipUser/get_info', {
      data: _bale('get_info', { token: token })
    })
  }
  // 绑定上一级
  addBossFans() {
    const _this = this
    const bossid = wx.getStorageSync('bossid')
    const params = {
      userCode: bossid ? bossid : ''
    }
    return new Promise(function(resolve, reject) {
      _this
        .postRequest(SHARE_API + '/vipUser/add_fans', {
          data: _bale('add_fans', params)
        })
        .then(res => {
          //  成功
          wx.removeStorageSync('bossid')
          resolve()
        })
        .catch(err => {
          console.log('addBossFans err', err)
          reject(err)
        })
    })
  }
  // 圣诞活动七天
  sevenSign(params) {
    return this.postRequest(SHARE_API + '/task/sevenSign', {
      data: _bale('sevenSign', params)
    })
  }
  // 查询圣诞活动七天
  querySevenSign(params) {
    return this.postRequest(SHARE_API + '/task/querySevenSign', {
      data: _bale('querySevenSign', params)
    })
  }

  //预约专场
  selectAppointment(params) {
    return this.postRequest(SHARE_API + '/applietLazy/selectAppointment', {
      data: _bale('selectAppointment', params)
    })
  }

  //获取抽奖号码
  selectActivityNumber(params) {
    return this.postRequest(SHARE_API + '/applietLazy/selectActivityNumber', {
      data: _bale('selectActivityNumber', params)
    })
  }

  //查询抽奖
  selectNumberByUserId(params) {
    return this.postRequest(SHARE_API + '/applietLazy/selectNumberByUserId', {
      data: _bale('selectNumberByUserId', params)
    })
  }
  // 转盘
  signWheel(params) {
    return this.postRequest(SHARE_API + '/task/turnSevenSign', {
      data: _bale('turnSevenSign', params)
    })
  }
  // 查询新年抽奖页面九宫格翻牌
  getNewYear(params) {
    return this.postRequest(SHARE_API + '/year/queryNewYear', {
      data: _bale('queryNewYear', params)
    })
  }
  // 点击开始抽奖
  cardGameStart(params) {
    return this.postRequest(SHARE_API + '/year/luckDraw', {
      data: _bale('luckDraw', params)
    })
  }
  // 翻牌
  getCardAwardInfo(params) {
    return this.postRequest(SHARE_API + '/year/flop', {
      data: _bale('flop', params)
    })
  }
  // 领取奖品
  getAward(params) {
    return this.postRequest(SHARE_API + '/year/receivePrize', {
      data: _bale('receivePrize', params)
    })
  }
  // 助力
  helpGetCardAward(params) {
    return this.postRequest(SHARE_API + '/year/assistance', {
      data: _bale('assistance', params)
    })
  }
  // 记录
  getAwardRecords(params) {
    return this.postRequest(SHARE_API + '/year/records', {
      data: _bale('records', params)
    })
  }
  //红包雨时间查询
  redRain(params) {
    return this.postRequest(SHARE_API + '/red/redRain', {
      data: _bale('redRain', params)
    })
  }
  //红包雨领金币
  redRainGold(params) {
    return this.postRequest(SHARE_API + '/red/redRainGold', {
      data: _bale('redRainGold', params)
    })
  }
  // 查询活动是否开启
  getCardStatus(params) {
    return this.postRequest(SHARE_API + '/year/activity', {
      data: _bale('activity', params)
    })
  }

}
export { AppModel }
